﻿using Airon.Extras.DatabaseAccessor.Dapper.Internal;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Airon.Dapper.Internal
{
   public  class SqlDataBaseConfigConstructor
    {

        public SqlDataBaseConfig[] configs { get; set; }

        public string sqlProvider { get; set; }

        #region  多数据库初始化
        /// <summary>
        ///  初始化Dapper配置  
        /// </summary>
        /// <param name="sqlProvider"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public IEnumerable<IDbConnectionConfig> InitDapperRepository()
        {
                List<IDbConnectionConfig> _dbList = new List<IDbConnectionConfig>();
                //这里不能直接创建 得等到实际获取的时候 再进行获取数据库连接
                configs.ToList().ForEach(s =>
                {
                    //添加数据库连接对象
                    //var dbConnection = Activator.CreateInstance(SqlProvider.GetDbConnectionType(sqlProvider), new[] { s.ConnectionString }) as IDbConnection;
                    _dbList.Add(new IDbConnectionConfig(s.dbType, s.ConnectionString));
                });
                 return _dbList;
        }
        #endregion
    }
}
